#include <stdio.h>
#include "student_lib.h"
#define STUDENTS_MAX_LENGTH 20
static struct student students[STUDENTS_MAX_LENGTH];
static int position = -1;
//static int students_length = 0;
void add(struct student *s)
{
	if(position >= (STUDENTS_MAX_LENGTH - 1))
	{
		printf("students is full\n");
		return;
	}
	position++;
	//students_length++;
	students[position] = *s;
}
void print_new_student(void)
{
	if(position == -1)
	{
		printf("no students\n");
		return;
	}
	print_student(&students[position]);
}
void print_student_table_head(void)
{
	printf("id\tname\tsex\tage\n");
}
void print_student(struct student *s)
{
	print_student_table_head();
	printf("%d\t%s\t%s\t%d\n",(*s).id,(*s).name,(*s).sex,(*s).age);
}
void print_all_student(void)
{
	print_student_table_head();
	for(int i = 0;i <= position;i++)
	{
		printf("%d\t%s\t%s\t%d\n",students[i].id,students[i].name,students[i].sex,students[i].age);
	}
}
void del_by_id(int id)
{
	if(position == -1)
	{
		printf("no students\n");
		return;
	}
	int is_found = 0;
	for(int i =0;i < position;i++)
	{
		if(is_found == 0 && id == students[i].id)
		{
			is_found = 1;
		}
		if(is_found)
		{
			students[i] = students[i+1];
		}
	}
	position-=is_found;
}
